<?php
include APPLICATION_PATH."/models/base/ProductBase.php";

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class Model_Product extends Model_ProductBase{
    
}
class Model_ProductMapper extends Model_ProductMapperBase{
    public function findIn($id) {
        $db = Zend_Db_Table::getDefaultAdapter();
        $select= 'select id from product where id='.$id;
        $stmt=$db->query($select);
        $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $entries   = array();
        foreach ($rows as $row){
            $entry = new Model_Product();
            $entry->setId($row->id)
                ->setId($row->id);
             $entries[] = $entry;
        }
        return $entries;
    }
    public function findbyid($id){
        $db = Zend_Db_Table::getDefaultAdapter();
        $select= 'select * from product where id='.$id.'';
        $stmt=$db->query($select);
        $row = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $entry = new Model_Product();
        if($row==NULL){
            return NULL;
        } else {
        $entry->setId($row[0]->id)
                    ->setId($row[0]->id)
                    ->setName($row[0]->name)
                    ->setProduct_Cat_Id($row[0]->product_cat_id)
                    ;
        }
        return $entry;  
    }
    public function getProductByCategoryId($product_cat_id) {
        $db = Zend_Db_Table::getDefaultAdapter();
        $select= 'select * from product where product_cat_id='.$product_cat_id;
        $stmt=$db->query($select);
        $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $entries   = array();
        foreach ($rows as $row){
            $entry = new Model_Product();
            $entry->setId($row->id)
                ->setId($row->id);
             $entries[] = $entry;
        }
        return $entries;
    }
     public function fetchAllPublished(){
        $db = Zend_Db_Table::getDefaultAdapter();
        $select=$db->select()
                ->from('product');
                //->where('status=1');
        $stmt=$select->query();
        $rows = $stmt->fetchAll(PDO::FETCH_CLASS);
        $stmt->closeCursor();
        $entries   = array();
        foreach ($rows as $row) {
            $entry = new Model_Product();
            $entry->setId($row->id)
                ->setId($row->id)
                ->setName($row->name)
                ->setPrice($row->price) 
                ->setPicture($row->picture)
                ->setProduct_Cat_Id($row->product_cat_id)
                ->setCreated($row->created)
                ->setCreated_By($row->created_by)
                ->setModified($row->modified)
                ->setModified_By($row->modified_by)
                ->setOrder($row->order)
                ->setStatus($row->status);
            $entries[] = $entry;
        }
        return $entries;
    }
    
    
}

